package com.immediatus.graphics.factories;


import com.immediatus.graphics.contracts.ITexture;
import com.immediatus.graphics.contracts.ITextureAtlas;
import com.immediatus.graphics.contracts.ITextureAtlasSource;
import com.immediatus.graphics.texture.region.TabledTextureRegion;
import com.immediatus.graphics.texture.region.TextureRegion;

public class TextureRegionFactory{

    public static TextureRegion extractFromTexture(final ITexture texture_, final int texturePositionX_, final int texturePositionY_, final int width_, final int height_, final boolean textureRegionBufferManaged_){
        final TextureRegion textureRegion = new TextureRegion(texture_, texturePositionX_, texturePositionY_, width_, height_);
        textureRegion.setTextureRegionBufferManaged(textureRegionBufferManaged_);
        return textureRegion;
    }

    public static <T extends ITextureAtlasSource> TextureRegion createFromSource(final ITextureAtlas<T> textureAtlas_, final T textureAtlasSource_, final int x_, final int y_, final boolean managed_){
        final TextureRegion textureRegion = new TextureRegion(textureAtlas_, x_, y_, textureAtlasSource_.getWidth(), textureAtlasSource_.getHeight());
        textureAtlas_.addTextureAtlasSource(textureAtlasSource_, textureRegion.getX(), textureRegion.getY());
        textureRegion.setTextureRegionBufferManaged(managed_);
        return textureRegion;
    }

    public static <T extends ITextureAtlasSource> TabledTextureRegion createTabledFromSource(final ITextureAtlas<T> textureAtlas_, final T textureAtlasSource_, final int x_, final int y_, final int tileColumns_, final int tileRows_, final boolean managed_){
        final TabledTextureRegion tabledTextureRegion = new TabledTextureRegion(textureAtlas_, x_, y_, textureAtlasSource_.getWidth(), textureAtlasSource_.getHeight(), tileColumns_, tileRows_);
        textureAtlas_.addTextureAtlasSource(textureAtlasSource_, tabledTextureRegion.getX(), tabledTextureRegion.getY());
        tabledTextureRegion.setTextureRegionBufferManaged(managed_);
        return tabledTextureRegion;
    }
}
